package com.sun.aviatortest;

import com.googlecode.aviator.AviatorEvaluator;

import java.util.HashMap;
import java.util.Map;

public class AviatorTest1 {
    public static void main(String[] args) {
        test2();
    }

    public  static void test1(){
        Object exec = AviatorEvaluator.exec("22+1+100");
        System.out.println(exec);
    }

    public static void test2(){
        String  myname = "Lily";
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("myname",myname);

        //方法一：
        String result1 = (String)
                AviatorEvaluator.execute(" 'hello '+ myname",map);
        System.out.println(result1);
        //方法二：
        Object result11 = AviatorEvaluator.exec("'hello '+ myname",myname);
        System.out.println(result11.toString());

        String result2 = (String)
                AviatorEvaluator.execute("\"a\'b\'c\"");//输出：a'b'c
        String result3 = (String)
                AviatorEvaluator.execute("'a\"b\"c'");//输出：a"b"c
        String result4 = (String)
                AviatorEvaluator.execute("'a\"b\"c' + 3");//输出：a"b"c3
        String result5 = (String)
                AviatorEvaluator.execute("'a\"b\"c' + hello");//输出：a"b"cnull
    }
}
